*Set working directory
if c(username)=="" { //insert username
cd "" // insert root path
}

if c(username)=="jmc4qg" { 
cd "/Users/jmc4qg/The Lab Dropbox/Jonathan Colmer/ShotSpotter_env/Journal_submissions/ReStat/Replication Folder" 
}

if c(username)=="jonathancolmer" { 
cd "/Users/jonathancolmer/The Lab Dropbox/Jonathan Colmer/ShotSpotter_env/Journal_submissions/ReStat/Replication Folder"
}

*Create Annual RTC Policy Indicator*
 
use "Processed Data/monthly_gun_policies_UCR.dta", clear
gen MP = 0
replace MP = 1 if may_issue == 1 | prohibited == 1
collapse (max) MP, by(fips year)
rename fips st_fips
save "Processed Data/annual_gun_policies.dta", replace

use "Raw Data/County Population/uswbo19agesadj.dta", clear

collapse (sum) pop, by(st stfips county year)

rename county fips 

collapse (sum) pop, by(st stfips fips year)

rename stfips fips_st
destring fips_st, replace
destring fips, replace
save "Processed Data/county_total_pop.dta", replace


use "Processed Data/county_total_pop.dta", clear

rename fips_st st_fips

merge m:1 st_fips year using "Processed Data/annual_gun_policies.dta"
keep if _m == 3
drop _m

** 2016 population, 1991 policy regime **

preserve 
gen MP_1991 = MP if year == 1991
bys st_fips: egen mp_1991 = max(MP_1991)

egen total_pop_2016 = total(pop) if year == 2016
egen total_pop_LP_2016 = total(pop) if year == 2016 & mp_1991 == 0
gen LP_share = total_pop_LP_2016/total_pop_2016
sum LP_share 

keep if mp_1991 == 0

gen pop_100k = pop/100000

gen homicides_per_degree_DiDiT = 0.000349*365.25*pop_100k 
gen homicides_per_degree_DiT = 0.000511*365.25*pop_100k 

collapse (sum) homi* pop_100k, by(year)

sum homi* if year == 2016
restore

** 2016 population, 2016 policy regime **

preserve 
egen total_pop_2016 = total(pop) if year == 2016
egen total_pop_LP_2016 = total(pop) if year == 2016 & MP == 0
gen LP_share = total_pop_LP_2016/total_pop_2016
sum LP_share 

keep if MP == 0

gen pop_100k = pop/100000

gen homicides_per_degree_DiDiT = 0.000349*365.25*pop_100k 
gen homicides_per_degree_DiT = 0.000511*365.25*pop_100k 

gen WTP_homicides_per_degree_DiDiT = 11.3*homicides_per_degree_DiDiT
gen WTP_homicides_per_degree_DiT = 11.3*homicides_per_degree_DiT

collapse (sum) homi* WTP* pop_100k, by(year)

sum homi* if year == 2016
sum WTP* if year == 2016
restore

** Social Benefit Comparisons 

** Police Officers - Chalfin and McCrary (2018)

disp 3380/0.263397

** SAT facilities - Bondurant et al. (2018)

disp 3380/8.22

** Mental Healthcare Offices - Deza et al. (2022)

disp 3380/0.479300

** READI program - Heler et al. (2023)

disp 3380/0.970890
